﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Silverlight.Testing;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace SilverlightTesting
{
    [TestClass]
    public class TestPasswordManager
    {
        [TestMethod]
        public void TestGetSetPassword()
        {
            ChessOnline.PasswordManager pwm = new ChessOnline.PasswordManager();

            pwm.SetPassword("naughty dog");
            Assert.AreEqual("naughty dog", pwm.GetPassword());

            pwm.SetPassword("");
            Assert.AreEqual("", pwm.GetPassword());
        }

        [TestMethod]
        public void TestGetMaskedPassword0()
        {
            ChessOnline.PasswordManager pwm = new ChessOnline.PasswordManager();

            pwm.SetPassword("naughty dog");
            Assert.AreEqual("**********g", pwm.GetMaskedPassword());

            pwm.SetPassword("");
            Assert.AreEqual("", pwm.GetMaskedPassword());

            pwm.SetPassword("g");
            Assert.AreEqual("g", pwm.GetMaskedPassword());
        }

        [TestMethod]
        public void TestGetMaskedPassword1()
        {
            ChessOnline.PasswordManager pwm = new ChessOnline.PasswordManager();

            pwm.SetPassword("naughty dog");
            Assert.AreEqual("++++++++++g", pwm.GetMaskedPassword('+'));

            pwm.SetPassword("");
            Assert.AreEqual("", pwm.GetMaskedPassword('+'));

            pwm.SetPassword("+");
            Assert.AreEqual("+", pwm.GetMaskedPassword('+'));

            pwm.SetPassword("h");
            Assert.AreEqual("h", pwm.GetMaskedPassword('+'));
        }

        [TestMethod]
        public void TestSymbolAdded0()
        {            
            ChessOnline.PasswordManager pwm = new ChessOnline.PasswordManager();

            pwm.SetPassword("abc");
            pwm.SymbolAdded('d');
            Assert.AreEqual("abcd", pwm.GetPassword());
            Assert.AreEqual("***d", pwm.GetMaskedPassword());

            pwm.SetPassword("naughty dog");
            pwm.SymbolAdded('.');
            Assert.AreEqual("naughty dog.", pwm.GetPassword());
            Assert.AreEqual("***********.", pwm.GetMaskedPassword());

            pwm.SetPassword("");
            pwm.SymbolAdded('b');
            Assert.AreEqual("b", pwm.GetPassword());
            Assert.AreEqual("b", pwm.GetMaskedPassword());
        }

        [TestMethod]
        public void TestSymbolAdded1()
        {
            ChessOnline.PasswordManager pwm = new ChessOnline.PasswordManager();

            pwm.SetPassword("abc");
            pwm.SymbolAdded('d');
            Assert.AreEqual("abcd", pwm.GetPassword());
            Assert.AreEqual("***d", pwm.GetMaskedPassword());

            pwm.SetPassword("naughty dog");
            pwm.SymbolAdded('.');
            Assert.AreEqual("naughty dog.", pwm.GetPassword());
            Assert.AreEqual("+++++++++++.", pwm.GetMaskedPassword('+'));

            pwm.SetPassword("");
            pwm.SymbolAdded('b');
            Assert.AreEqual("b", pwm.GetPassword());
            Assert.AreEqual("b", pwm.GetMaskedPassword('+'));
        }

        [TestMethod]
        public void TestSymbolDeleted()
        {
            ChessOnline.PasswordManager pwm = new ChessOnline.PasswordManager();
            pwm.SetPassword("abc");
            pwm.SymbolDeleted();
            Assert.AreEqual("ab", pwm.GetPassword());
            Assert.AreEqual("*b", pwm.GetMaskedPassword());

            pwm.SetPassword("naughty dog");
            pwm.SymbolDeleted();
            Assert.AreEqual("naughty do", pwm.GetPassword());
            Assert.AreEqual("*********o", pwm.GetMaskedPassword());

            pwm.SetPassword("");
            pwm.SymbolDeleted();
            Assert.AreEqual("", pwm.GetPassword());
            Assert.AreEqual("", pwm.GetMaskedPassword());

            pwm.SetPassword("b");
            pwm.SymbolDeleted();
            Assert.AreEqual("", pwm.GetPassword());
            Assert.AreEqual("", pwm.GetMaskedPassword());
        }

        [TestMethod]
        public void TestGetPasswordLength()
        {
            ChessOnline.PasswordManager pwm = new ChessOnline.PasswordManager();
            pwm.SetPassword("abc");
            Assert.AreEqual(3, pwm.GetPasswordLength());

            pwm.SetPassword("naughty dog");
            Assert.AreEqual(11, pwm.GetPasswordLength());

            pwm.SetPassword("");
            Assert.AreEqual(0, pwm.GetPasswordLength());

            pwm.SetPassword("abc");
            pwm.SymbolAdded('d');
            Assert.AreEqual(4, pwm.GetPasswordLength());

            pwm.SetPassword("naughty dog");
            pwm.SymbolAdded('.');
            Assert.AreEqual(12, pwm.GetPasswordLength());

            pwm.SetPassword("");
            pwm.SymbolDeleted();
            Assert.AreEqual(0, pwm.GetPasswordLength());

            pwm.SetPassword("b");
            pwm.SymbolDeleted();
            Assert.AreEqual(0, pwm.GetPasswordLength());
        }

        [TestMethod]
        public void TestClearPassword()
        {
            ChessOnline.PasswordManager pwm = new ChessOnline.PasswordManager();
            
            pwm.SetPassword("abc");
            pwm.ClearPassword();
            Assert.AreEqual(0, pwm.GetPasswordLength());
            Assert.AreEqual("", pwm.GetPassword());
            Assert.AreEqual("", pwm.GetMaskedPassword());
            Assert.AreEqual("", pwm.GetMaskedPassword('+'));

            pwm.SetPassword("");
            pwm.ClearPassword();
            Assert.AreEqual(0, pwm.GetPasswordLength());
            Assert.AreEqual("", pwm.GetPassword());
            Assert.AreEqual("", pwm.GetMaskedPassword());
            Assert.AreEqual("", pwm.GetMaskedPassword('+'));

            pwm.SetPassword("a");
            pwm.ClearPassword();
            Assert.AreEqual(0, pwm.GetPasswordLength());
            Assert.AreEqual("", pwm.GetPassword());
            Assert.AreEqual("", pwm.GetMaskedPassword());
            Assert.AreEqual("", pwm.GetMaskedPassword('+'));

            pwm.SetPassword("/n");
            pwm.ClearPassword();
            Assert.AreEqual(0, pwm.GetPasswordLength());
            Assert.AreEqual("", pwm.GetPassword());
            Assert.AreEqual("", pwm.GetMaskedPassword());
            Assert.AreEqual("", pwm.GetMaskedPassword('+'));
        }
    }
}